
def joinPath(*parts):
	"""join path elements"""
	parts=filter(None, parts)
	if len(parts)==0:
		return u''
	if len(parts)==1:
		return parts[0]
	elif len(parts)==2:
		return parts[0].rstrip('/')+'/'+parts[1].lstrip('/')
	else:
		result=parts[0].rstrip('/')+'/'
		for part in parts[1:-1]:
			result+=part.strip('/')+'/'
		result+=parts[-1].lstrip('/')
		return result
	return '' 	

def copy(srcFs, destFs, srcFileName, destFileName=None, content_type='application/octet-stream'):
	"""copy file from one filesystem to another"""
	if not destFileName: 
		destFileName=srcFileName
	inputStream=srcFs.open(srcFileName, 'rb')
	outputStream=destFs.open(destFileName, 'wb')
	outputStream.setContentType(inputStream.getContentType())
	block=inputStream.read(8190)
	while block:
		outputStream.write(block)
		block=inputStream.read(8190)
	return outputStream.close()
	
